package com.bazaaroid.server.gae.api.resources.partner;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

import com.bazaaroid.server.gae.core.dao.partner.CategoryDAO;
import com.bazaaroid.server.gae.core.dto.partner.AllEntitiesDTO;
import com.bazaaroid.server.gae.core.dto.partner.CategoryDTO;
import com.bazaaroid.server.gae.core.dto.partner.AllEntitiesDTO.CategoriesDTO;
import com.bazaaroid.server.gae.core.ioc.GuiceFactory;
import com.bazaaroid.server.gae.core.persistence.model.partner.Category;
import com.google.appengine.api.datastore.KeyFactory;

@Path("/category/")
public class CategoryResource {

	@GET
	@Produces( { "application/xml", "application/json" })
	@Path("/{id}")
	public CategoryDTO getById(@PathParam ("id") Long id) {
		CategoryDAO categoryDAO = GuiceFactory.getInjector()
			.getInstance(CategoryDAO.class);
		Category category = categoryDAO.getById(KeyFactory.createKey(
				Category.class.getSimpleName(), id));
		return new CategoryDTO(category);
	}

	@GET
	@Produces( { "application/xml", "application/json" })
	@Path("/all/")
	public CategoriesDTO getAllCategories() {
		CategoryDAO categoryDAO = GuiceFactory.getInjector()
			.getInstance(CategoryDAO.class);
		List<Category> categories = categoryDAO.getAll();
		return new AllEntitiesDTO.CategoriesDTO(categories);
	}
}
